﻿// JScript 文件
// 样表类别
function EvalItems (RID, EvalName, Remarks)
{
    this.RID = RID;
    this.EvalName = EvalName;
    this.Remarks = Remarks;
};

// 样表
function Templates (RID, EvalItemId, TemplateName, TemplateStyle, EvalType, TemplateLevel)
{
    this.RID = RID;
    this.EvalItemId = EvalItemId;
    this.TemplateName = TemplateName;
    this.TemplateStyle = TemplateStyle;
    this.EvalType = EvalType;
    this.TemplateLevel = TemplateLevel;
};

// 题目类别
function QuesitonTypes (RID, TemplateID, QtName, QtPosition)
{
    this.RID = RID;
    this.TemplateID = TemplateID;
    this.QtName = QtName;
    this.QtPosition = QtPosition;
};

// 题目
function QuestionItems (RID, QtTypeID, QiType, QiContent, QiPosition, QiOpts, QiScore)
{
    this.RID = RID;
    this.QtTypeID = QtTypeID;
    this.QiType = QiType;
    this.QiContent = QiContent;
    this.QiPosition = QiPosition;
    this.QiOpts = QiOpts;
    this.QiScore = QiScore;
};

// 选项
function Opt (index, title, score)
{
    this.index = index;
    this.title = title;
    this.score = score;
}

//获取元素的纵坐标
function getTop(e){
    var offset=e.offsetTop;
    if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
    return offset;
}
//获取元素的横坐标
function getLeft(e){
    var offset=e.offsetLeft;
    if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
    return offset;
}

function getCoord(obj, offsetLeft, offsetTop){
    var orig = obj;
    var left = 0;
    var top = 0;
    if(offsetLeft) left = offsetLeft;
    if(offsetTop) top = offsetTop;
    
    setTimeout(obj, 5);
    
    if(orig.offsetParent){
        left += obj.offsetLeft;
        top += obj.offsetTop;
        while (obj = obj.offsetParent) {
            left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
            top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
        }
    }
    return {left:left, top:top,
            width:orig.offsetWidth, height:orig.offsetHeight};
}

//function getCoord(objId){
//    //alert(objId);
//    var obj = document.getElementById(objId);
//    var orig = obj;
//    var left = 0;
//    var top = 0;
//    
//    setTimeout(obj, 5);
//    
//    if(orig.offsetParent){
//        left += obj.offsetLeft;
//        top += obj.offsetTop;
//        while (obj = obj.offsetParent) {
//            left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
//            top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
//        }
//    }
//    return {left:left, top:top,
//            width:orig.offsetWidth, height:orig.offsetHeight};
//}  

//  菜单类
function Menu(menuName, menuListName){
    this.menuName = menuName;
    this.menuListName = menuListName;
    this.objMenu = document.getElementById(this.menuName);
    this.objMenuList = document.getElementById(this.menuListName);
	this.objFocus = true;
	
	this.Show = function(){
		var hight = this.objMenu.offsetHeight;
		if(this.objMenu == null)
		    this.objMenu = document.getElementById(this.menuName);
		var rect = getCoord(this.objMenu);
		
		this.objMenuList.style.top = rect.top + hight;
		this.objMenuList.style.left = rect.left;
//			this.objMenuList.style.top = getTop(this.objMenu) + hight - document.body.scrollTop;
//			this.objMenuList.style.left = getLeft(this.objMenu);
		
		this.objMenuList.style.display = "block";
		this.objFocus = true;
	}
	
	this.Hide = function(){
		this.objMenuList.style.display = "none";
	}
//		this.objMenu.onblur = function (){
//			Menu.objFocus = false;
//			this.style.display = "none";
//		}
//		this.objMenuList.onblur = function (){
//			Menu.objListFocus = false;
//			if(!Menu.objFocus)
//				this.style.display = "none";
//		}
}
	
//  菜单管理类
function MenuManager(){
    MenuManager.menus = new Array();
	MenuManager.activeMenu = null;  // 当前激活的菜单
		// 添加菜单
		MenuManager.prototype.AddMenu = function(menuName, menuListName){
		    for(var i = 0; i < MenuManager.menus.length; i++ ) {
		        if(MenuManager.menus[i].menuName == menuName)
		            return;
		    }
			MenuManager.menus.push(new Menu(menuName, menuListName));
		}
		
		// 显示菜单
		MenuManager.prototype.ShowMenu = function(menuName){
			for (var i = 0; i < MenuManager.menus.length; i++) {
				//alert(MenuManager.menus[i].menuName);
				if (MenuManager.menus[i].menuName == menuName) {
					MenuManager.menus[i].Show();
					MenuManager.activeMenu = MenuManager.menus[i];
				}
				else {
					MenuManager.menus[i].Hide();
				}
			}
		}
		
		// 隐藏菜单
		MenuManager.prototype.HideMenu = function(menuName){
			for (var i = 0; i < MenuManager.menus.length; i++) {
				if (MenuManager.menus[i].menuName == menuName) {
					MenuManager.menus[i].Hide();
					break;
				}
			}
		}
		
        // 初始化菜单
        MenuManager.prototype.InitMenu = function(menuPopEvent){

//	                switch (menuPopEvent) {
//	                    case "click":
//	                        for (var i = 0; i < MenuManager.menus.length; i++) {
//								var index = i;
//	                        	MenuManager.menus[index].objMenu.onclick = function(){
//									MenuManager.menus[index].Show();
//									//MenuManager.ShowMenu(MenuManager.menus[index].menuName);
//								}
//	                        }
//	                        break;
//	                    case "mouseover":
//	                        for (var i = 0; i < MenuManager.menus.length; i++) {
//								var index = i;
//	                        	MenuManager.menus[index].objMenu.onmouseover = function(){
//									MenuManager.ShowMenu(MenuManager.menus[index].menuName);
//								}
//	                        }
//	                        break;
//	                    default:
//	                        break;
//	                }
        }  

};


// 显示对话框(全遮罩)
function ShowMessageWithCallBack(title, message, type) {
    self.parent.leftFrame.showMask();
    showMassgeBox(title, message, type, 
        function () {
        	self.parent.leftFrame.hideMask();
        });
};